<?php

namespace common\Factory\Redis;

use common\Factory\ServerInterface;
use common\Factory\Factory;

class RedisServer implements ServerInterface {
    
    private $_config;
    private $_host = '127.0.0.1';
    private $_port = '6379';
    
    function __construct() {
        $config = \core\init\init::getConfig();
        if(isset($config['redis'])) {
            $this->_host = $config['redis']['host'];
            $this->_port = $config['redis']['port'];
        }
    }
    
    public function getObj() {
        $redis = new \Redis();
        $redis->connect($this->_host, $this->_port);
        $isConnect = true;
        $isConnect = $redis->isConnected() === false ? false : true;
        $isConnect === false && Factory::getServer('MqWriteLog')->send('redis connect failed');
        $isConnect === true && $redis->select(0);
        
        return $isConnect === true ? $redis : false;
    }
}